package com.ruoyi.project.crm.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.crm.domain.CrmSuncode;
import com.ruoyi.project.crm.service.ICrmSuncodeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 二维码存放地址Controller
 * 
 * @author ruoyi
 * @date 2020-06-29
 */
@RestController
@RequestMapping("/capi/suncode")
public class CrmSuncodeController extends BaseController
{
    @Autowired
    private ICrmSuncodeService crmSuncodeService;

    /**
     * 查询二维码存放地址列表
     */
    @PreAuthorize("@ss.hasPermi('capi:suncode:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmSuncode crmSuncode)
    {
        startPage();
        List<CrmSuncode> list = crmSuncodeService.selectCrmSuncodeList(crmSuncode);
        return getDataTable(list);
    }

    /**
     * 导出二维码存放地址列表
     */
    @PreAuthorize("@ss.hasPermi('capi:suncode:export')")
    @Log(title = "二维码存放地址", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CrmSuncode crmSuncode)
    {
        List<CrmSuncode> list = crmSuncodeService.selectCrmSuncodeList(crmSuncode);
        ExcelUtil<CrmSuncode> util = new ExcelUtil<CrmSuncode>(CrmSuncode.class);
        return util.exportExcel(list, "suncode");
    }

    /**
     * 获取二维码存放地址详细信息
     */
    @PreAuthorize("@ss.hasPermi('capi:suncode:query')")
    @GetMapping(value = "/{sid}")
    public AjaxResult getInfo(@PathVariable("sid") Long sid)
    {
        return AjaxResult.success(crmSuncodeService.selectCrmSuncodeById(sid));
    }

    /**
     * 新增二维码存放地址
     */
    @PreAuthorize("@ss.hasPermi('capi:suncode:add')")
    @Log(title = "二维码存放地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmSuncode crmSuncode)
    {
        return toAjax(crmSuncodeService.insertCrmSuncode(crmSuncode));
    }

    /**
     * 修改二维码存放地址
     */
    @PreAuthorize("@ss.hasPermi('capi:suncode:edit')")
    @Log(title = "二维码存放地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmSuncode crmSuncode)
    {
        return toAjax(crmSuncodeService.updateCrmSuncode(crmSuncode));
    }

    /**
     * 删除二维码存放地址
     */
    @PreAuthorize("@ss.hasPermi('capi:suncode:remove')")
    @Log(title = "二维码存放地址", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sids}")
    public AjaxResult remove(@PathVariable Long[] sids)
    {
        return toAjax(crmSuncodeService.deleteCrmSuncodeByIds(sids));
    }
}
